﻿/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\MicrosoftAjax.js" />
/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.debug.js" />

if (window.external && 'msIsSiteMode' in window.external) {
    ExecuteOrDelayUntilScriptLoaded(LoadJumpLists, "sp.js");
}

//if (navigator.appVersion.match('MSIE') != '') {
//    version = parseFloat(navigator.appVersion.split('MSIE')[1]);
//    if (version >= 9) {
//        
//    }
//}

function LoadJumpLists() {
    this.ctx = new SP.ClientContext.get_current();
    this.quickLaunch = ctx.get_web().get_navigation().get_quickLaunch();
    this.ctx.load(quickLaunch);
    this.ctx.executeQueryAsync(Function.createDelegate(this, this.LoadJumpLists_navLoadedSuccess), Function.createDelegate(this, this.LoadJumpLists_navLoadedFail));
}

function LoadJumpLists_navLoadedSuccess(sender, args) {
    var groupCount = this.quickLaunch.get_count();
    this.childNodes = new Array(groupCount);
    for (i = 0; i < groupCount; i++) {
        this.childNodes[i] = this.quickLaunch.get_item(i).get_children();
        this.ctx.load(this.childNodes[i]);
    }
    this.ctx.executeQueryAsync(Function.createDelegate(this, this.LoadJumpLists_childrenLoadedSuccess), Function.createDelegate(this, this.LoadJumpLists_childrenLoadedFail));
}

function LoadJumpLists_childrenLoadedSuccess(sender, args) {
    window.external.msSiteModeClearJumplist();
    window.external.msSiteModeCreateJumplist("Quick Launch");
    var groupCount = this.quickLaunch.get_count();
    for (i = groupCount - 1; i >= 0; i--) {
        if (this.quickLaunch.get_item(i).get_url() != "")
        {
            window.external.msSiteModeAddJumpListItem(this.quickLaunch.get_item(i).get_title(), this.quickLaunch.get_item(i).get_url(), '/_layouts/images/socialtag.ico');
        }
        var childCount = this.childNodes[i].get_count();
        for (c = childCount - 1; c >= 0; c--) {
            window.external.msSiteModeAddJumpListItem(this.childNodes[i].get_item(c).get_title(), this.childNodes[i].get_item(c).get_url(), '/_layouts/images/socialtag.ico');
        }
    }
    window.external.msSiteModeShowJumplist();
}

function LoadJumpLists_childrenLoadedFail(sender, args) {
    alert('Error loading Jump List data: Unable to load navigation child nodes.');
}

function LoadJumpLists_navLoadedFail(sender, args) {
    alert('Error loading Jump List data: Unable to load the web object.');
}
